// index.js
const {
  schoolListByLoginUser,
} = require('../../apiConfig/apiList/luban')
Page({
  data: {
    pageNum: 1,
    pageSize: 10,
    isEnd: false,
    schoolList: [],
  },
  onLoad(){
    this.getSchoolList()
  },
  getSchoolList(){
    if(this.data.isEnd)return;
    let that = this;
    let pageNum = this.data.pageNum;
    let pageSize = this.data.pageSize;
    let list = this.data.schoolList;
    let params = {
      keyword: '',
      status: '',
      pageNum: pageNum,
      pageSize: pageSize,
      orderByColumn: 'create_time',
      isAsc: 'desc',
    };
    schoolListByLoginUser(params).then(res=>{
      if(res.code == 200){
        let data = res.rows;
        this.setData({
          schoolList: list.concat(data)
        });
        if(res.tatal == 0){
          wx.showToast({
            title: '暂无学校！',
            icon: 'none',
            mask: true,
            success: () => {
              reject(err)
            }
          })
        }
        if(that.data.schoolList.length < res.total){
          pageNum++;
          this.setData({
            pageNum
          })
        }else{
          this.setData({
            isEnd: 'ture'
          });
        }
      }
    });
  }
})
